﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Tools;

namespace Mars2013plugin
{
    public partial class MarsTaskPaneRibbon
    {
        
        private void MarsTaskPaneRibbon_Load(object sender, RibbonUIEventArgs e)
        {
            editLinesToskip.Text = Globals.ThisAddIn.nLinesToSkip.ToString();
        }

        private void toggleButton1_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Inspector inspector = (Outlook.Inspector)e.Control.Context;
            WindowFormRegionCollection formRegions =
        Globals.FormRegions
            [Globals.ThisAddIn.Application.ActiveInspector()];
            RibbonToggleButton btn=(RibbonToggleButton)sender;
 //           formRegions.MarsFormRegion.Visible = btn.Checked;
            ShowHideAllMarsAnalyticsRegions(btn.Checked);
            if (btn.Checked)
            {
                btn.Label = "Hide All Mars Analytics Panels";
                btn.Image = Properties.Resources.round_delete;
            }
            else
            {
                btn.Label = "Show All Mars Analytics Panels";
                btn.Image = Properties.Resources.round_checkmark;
            }
   //         InspectorWrapper inspectWrapper = Globals.ThisAddIn.InspectorWrappers[inspector];
   //         CustomTaskPane taskPane = inspectWrapper.CustomTaskPane;
            //if (taskPane != null)
            //{
            //    taskPane.Visible = ((RibbonToggleButton)sender).Checked;
            //}
            
        }
        internal void ShowHideAllMarsAnalyticsRegions(bool bShow)
        {
            foreach (Microsoft.Office.Tools.Outlook.IFormRegion formRegion
                in Globals.FormRegions)
            {
                if (formRegion is MarsAnalyticsRegion)
                {
                    MarsAnalyticsRegion mars = (MarsAnalyticsRegion)formRegion;
                    mars.ShowHideMarsAnalyticsPanel(bShow);
                    
                }
            }

        }

        private void chktraillines_Click(object sender, RibbonControlEventArgs e)
        {
            Globals.ThisAddIn.bCheckTrailLines = chktraillines.Checked;
        }

        private void chkhyperlinks_Click(object sender, RibbonControlEventArgs e)
        {
            Globals.ThisAddIn.bCheckHyperLinks = chkhyperlinks.Checked;
        }

        private void checkBox1_Click(object sender, RibbonControlEventArgs e)
        {
            Globals.ThisAddIn.bCheckDateTime = chkhyperlinks.Checked;
        }

        private void editLinesToskip_TextChanged(object sender, RibbonControlEventArgs e)
        {
            string s = editLinesToskip.Text;
            int skipcnt;
            if (Int32.TryParse(s, out skipcnt) && (skipcnt <= 10) && (skipcnt >=0))
            {
                Globals.ThisAddIn.nLinesToSkip = skipcnt;
            }
        }
    }
}
